/**
 * 自定义FastImage,可以设置默认图
 *
 */
import React, {Component} from 'react';
import {Image} from 'react-native';
import FastImage from 'react-native-fast-image';
import {getUriImage} from '../../utils/util';

export default class MyFastImage extends Component {

    constructor(props) {
        super(props);
        this.state = {
            error: false,
        };
    }

    render() {
        const uri = getUriImage(this.props.source.uri);
        const defaultSource = this.props.defaultSource;
        const {error} = this.state;
        logger('地址', uri, error);
        // delete this.props.source;
        // delete this.props.defaultSource;
        if (IsNullOrEmpty(uri) || error) {
            logger('地址显示默认地址',defaultSource);
            return <Image {...this.props} source={defaultSource}/>;
        }
        return (
            <FastImage {...this.props}
                       onError={() => this.setState({error: true})}/>
        );
    }
}


